package Lab10.Q4;

import java.io.*;

public class Q4 {
    public static void main(String[] args) throws IOException {
        String input = "./input.txt";
        String output = "./output.txt";
        addLineNo(input, output);
    }
    public static void addLineNo(String inputPath, String outPath) throws IOException {
        File inputFile = new File(inputPath);
        File outputFile = new File(outPath);
        BufferedReader reader = null;
        FileWriter writer = null;
        StringBuilder output = new StringBuilder();
        try {
            reader = new BufferedReader(new FileReader(inputFile));
            int cnt=0;
            String line;
            while ((line = reader.readLine()) != null) {
                cnt++;
                output.append(cnt+"   ").append(line).append('\n');
            }
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            writer = new FileWriter(outputFile, false);//覆盖
            writer.append(output);
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
